package  com.rboat.exam.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rboat.common.annotation.Log;
import com.rboat.common.enums.BusinessType;
import com.rboat.exam.domain.ExamTestPaperQuestions;
import com.rboat.exam.service.IExamTestPaperQuestionsService;
import com.rboat.common.core.controller.BaseController;
import com.rboat.common.core.domain.AjaxResult;
import com.rboat.common.utils.poi.ExcelUtil;
import com.rboat.common.core.page.TableDataInfo;

/**
 * 试卷章节试题Controller
 * 
 * @author rboat
 * @date 2019-09-02
 */
@Controller
@RequestMapping("/exam/paperquestions")
public class ExamTestPaperQuestionsController extends BaseController
{
    private String prefix = "exam/paperquestions";

    @Autowired
    private IExamTestPaperQuestionsService examTestPaperQuestionsService;

    @RequiresPermissions("exam:paperquestions:view")
    @GetMapping()
    public String paperquestions()
    {
        return prefix + "/paperquestions";
    }

    /**
     * 查询试卷章节试题列表
     */
    @RequiresPermissions("exam:paperquestions:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamTestPaperQuestions examTestPaperQuestions)
    {
        startPage();
        List<ExamTestPaperQuestions> list = examTestPaperQuestionsService.selectExamTestPaperQuestionsList(examTestPaperQuestions);
        return getDataTable(list);
    }

    /**
     * 导出试卷章节试题列表
     */
    @RequiresPermissions("exam:paperquestions:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamTestPaperQuestions examTestPaperQuestions)
    {
        List<ExamTestPaperQuestions> list = examTestPaperQuestionsService.selectExamTestPaperQuestionsList(examTestPaperQuestions);
        ExcelUtil<ExamTestPaperQuestions> util = new ExcelUtil<ExamTestPaperQuestions>(ExamTestPaperQuestions.class);
        return util.exportExcel(list, "paperquestions");
    }

    /**
     * 新增试卷章节试题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试卷章节试题
     */
    @RequiresPermissions("exam:paperquestions:add")
    @Log(title = "试卷章节试题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamTestPaperQuestions examTestPaperQuestions)
    {
        return toAjax(examTestPaperQuestionsService.insertExamTestPaperQuestions(examTestPaperQuestions));
    }

    /**
     * 修改试卷章节试题
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ExamTestPaperQuestions examTestPaperQuestions = examTestPaperQuestionsService.selectExamTestPaperQuestionsById(id);
        mmap.put("examTestPaperQuestions", examTestPaperQuestions);
        return prefix + "/edit";
    }

    /**
     * 修改保存试卷章节试题
     */
    @RequiresPermissions("exam:paperquestions:edit")
    @Log(title = "试卷章节试题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamTestPaperQuestions examTestPaperQuestions)
    {
        return toAjax(examTestPaperQuestionsService.updateExamTestPaperQuestions(examTestPaperQuestions));
    }

    /**
     * 删除试卷章节试题
     */
    @RequiresPermissions("exam:paperquestions:remove")
    @Log(title = "试卷章节试题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examTestPaperQuestionsService.deleteExamTestPaperQuestionsByIds(ids));
    }
}
